import komand
from .schema import ViewConfigInput, ViewConfigOutput
# Custom imports below
from komand_malwareconfig.util.client import *


class ViewConfig(komand.Action):
    def __init__(self):
        super(self.__class__, self).__init__(
                name='view_config',
                description='View config for hash',
                input=ViewConfigInput(),
                output=ViewConfigOutput())

    def run(self, params={}):
        hashes = params.get("hashes")
        response = self.connection.client.view_config(hashes=hashes)

        status_code = response["response"]

        if not status_code == "200":
            raise Exception("Received non-200 status code")

        self.logger.info("Run: Received status code 200")

        results = list()
        items = response["items"]

        for key, value in items.items():
            results.append(value)

        return {"info": results}

    def test(self):
        """TODO: Test action"""
        return {}
